Crate svgtypes[][src]

Expand description

svgtypes is a collection of parsers, containers and writers for SVG 1.1 types.

Usage is simple as:

use svgtypes::Path;

let path: Path = "M10-20A5.5.3-4 110-.1".parse().unwrap();
assert_eq!(path.to_string(), "M 10 -20 A 5.5 0.3 -4 1 1 0 -0.1");

You can also use a low-level, pull-based parser:

use svgtypes::PathParser;

let p = PathParser::from("M10-20A5.5.3-4 110-.1");
for token in p {
    println!("{:?}", token);
}

You can also tweak an output format:

use svgtypes::{Path, WriteBuffer, WriteOptions};

let path_str = "M10-20A5.5.3-4 110-.1";
let path: Path = path_str.parse().unwrap();

let opt = WriteOptions {
    remove_leading_zero: true,
    use_compact_path_notation: true,
    join_arc_to_flags: true,
    .. WriteOptions::default()
};

assert_eq!(path.with_write_opt(&opt).to_string(), path_str);

Supported SVG types

SVG TypeRust TypeStorageParser
<color>ColorStack
<number>f64Stack
<length>LengthStack
<angle>AngleStack
<viewBox>ViewBoxStack
<path>PathHeapPathParser
<list-of-numbers>NumberListHeapNumberListParser
<list-of-lengths>LengthListHeapLengthListParser
<transform-list>TransformStackTransformListParser
<list-of-points>PointsHeapPointsParser
<paint>--Paint
  • All types implement from string (FromStr) and to string traits (Display, WriteBuffer).
  • The library doesn’t store transform list as is. It will premultiplied.
  • The paint type can only be parsed.

Benefits

  • Complete support of paths, so data like M10-20A5.5.3-4 110-.1 will be parsed correctly.
  • Access to pull-based parsers.
  • Pretty fast.

Limitations

  • Accepts only normalized values, e.g. an input text should not contain &#x20; or &data;.
  • All keywords must be lowercase. Case-insensitive parsing is supported only for colors (requires allocation for named colors).
  • The <color> followed by the <icccolor> is not supported. As the <icccolor> itself.
  • System colors, like fill="AppWorkspace", are not supported. They were deprecated anyway.
  • Implicit path commands are not supported. All commands will be parsed as explicit.
  • Implicit MoveTo commands will be automatically converted into explicit LineTo.

Safety

  • The library should not panic. Any panic considered as a critical bug and should be reported.
  • The library forbids unsafe code.

Alternatives

None.

Structs

Representation of the <angle> type.

Representation of the preserveAspectRatio attribute.

Representation of the <color> type.

A wrapper to use fmt::Display with WriteOptions.

Representation of the <length> type.

Representation of the <list-of-length> type.

A pull-based <list-of-length> parser.

Representation of the <list-of-numbers> type.

A pull-based <list-of-numbers> parser.

Representation of the SVG path data.

A pull-based path data parser.

Representation of the <list-of-points> type.

A pull-based <list-of-points> parser.

A streaming text parsing interface.

Representation of the <transform> type.

A pull-based <transform-list> parser.

Representation of the <viewBox> type.

Options for SVG types writing.

Enums

Representation of the align value of the preserveAspectRatio attribute.

List of all SVG angle units.

List of all errors.

List of all SVG length units.

A separator type for a list of values.

Representation of the <paint> type.

Representation of the fallback part of the <paint> type.

List of all path commands.

Representation of the path segment.

Transform list token.

Traits

A trait for fuzzy/approximate equality comparisons of float numbers.

A trait for fuzzy/approximate comparisons of float numbers.

A trait for writing data to the buffer.